<template>
  <div>
  <div class="relative min-h-screen flex">
    <div class="
                    flex flex-col
                    sm:flex-row
                    items-center
                    md:items-start
                    sm:justify-center
                    md:justify-start
                    flex-auto
                    min-w-0
                    bg-white
                ">
      <div class="
                        sm:w-1/2
                        xl:w-3/5
                        h-full
                        hidden
                        md:flex
                        flex-auto
                        items-center
                        justify-center
                        p-10
                        overflow-hidden
                        bg-purple-900
                        text-white
                        bg-no-repeat bg-cover
                        relative
                    " style="background-image: url(img/img.jpg)">
        <div class="
                            absolute
                            bg-gradient-to-b
                            from-indigo-600
                            to-blue-500
                            opacity-75
                            inset-0
                            z-0
                        "></div>
        <div class="w-full max-w-md z-10">
          <div class="sm:text-4xl xl:text-4xl font-bold leading-tight mb-6">{{title}}</div>
          <div class="sm:text-sm xl:text-md text-gray-200 font-normal"></div>
        </div>
        <ul class="circles">
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </div>
      <div class="
                        md:flex md:items-center md:justify-center
                        w-full
                        sm:w-auto
                        md:h-full
                        w-2/5
                        xl:w-2/5
                        p-8
                        md:p-10
                        lg:p-14
                        sm:rounded-lg
                        md:rounded-none
                        bg-white
                    ">
        <div class="max-w-md w-full mx-auto space-y-8">
          <div class="text-center">
            <h2 class="mt-6 text-3xl font-bold text-gray-900">欢迎回来</h2>
            <!--                            <p class="mt-2 text-sm text-gray-500">第三方登录</p>-->
          </div>
          <!--                        <div class="flex flex-row justify-center items-center space-x-3">-->
          <!--                            <a href="javascript:" class="-->
          <!--                                    w-11-->
          <!--                                    h-11-->
          <!--                                    items-center-->
          <!--                                    justify-center-->
          <!--                                    inline-flex-->
          <!--                                    rounded-2xl-->
          <!--                                    font-bold-->
          <!--                                    text-lg-->
          <!--                                    bg-blue-900-->
          <!--                                    hover:shadow-lg-->
          <!--                                    cursor-pointer-->
          <!--                                    transition-->
          <!--                                    ease-in-->
          <!--                                    duration-300-->
          <!--                                "><img class="w-4 h-4" src=""></a>-->
          <!--                            <a href="javascript:" class="-->
          <!--                                    w-11-->
          <!--                                    h-11-->
          <!--                                    items-center-->
          <!--                                    justify-center-->
          <!--                                    inline-flex-->
          <!--                                    rounded-2xl-->
          <!--                                    font-bold-->
          <!--                                    text-lg text-white-->
          <!--                                    bg-blue-400-->
          <!--                                    hover:shadow-lg-->
          <!--                                    cursor-pointer-->
          <!--                                    transition-->
          <!--                                    ease-in-->
          <!--                                    duration-300-->
          <!--                                "><img class="w-4 h-4" src=""></a>-->
          <!--                            <a href="javascript:" class="-->
          <!--                                    w-11-->
          <!--                                    h-11-->
          <!--                                    items-center-->
          <!--                                    justify-center-->
          <!--                                    inline-flex-->
          <!--                                    rounded-2xl-->
          <!--                                    font-bold-->
          <!--                                    text-lg text-white-->
          <!--                                    bg-blue-500-->
          <!--                                    hover:shadow-lg-->
          <!--                                    cursor-pointer-->
          <!--                                    transition-->
          <!--                                    ease-in-->
          <!--                                    duration-300-->
          <!--                                "><img src="" class="w-4 h-4"></a>-->
          <!--                        </div>-->
          <!--                        <div class="flex items-center justify-center space-x-2">-->
          <!--                            <span class="h-px w-16 bg-gray-200"></span>-->
          <!--                            <span class="text-gray-300 font-normal">使用账号密码登录</span>-->
          <!--                            <span class="h-px w-16 bg-gray-200"></span>-->
          <!--                        </div>-->
          <div class="mt-8 space-y-6" >
            <input type="hidden" name="remember" value="true">
            <div class="relative">
              <label class="ml-3 text-sm font-bold text-gray-700 tracking-wide">门店账号</label>
              <input
                v-model="loginForm.username"
                class="
                                        w-full
                                        text-base
                                        px-4
                                        py-2
                                        border-b border-gray-300
                                        focus:outline-none
                                        rounded-2xl
                                        focus:border-indigo-500
                                    " type="" placeholder="请输入账号">
            </div>
            <div class="mt-8 content-center">
              <label class="ml-3 text-sm font-bold text-gray-700 tracking-wide">密码</label>
              <input
                v-model="loginForm.password"
                class="
                                        w-full
                                        content-center
                                        text-base
                                        px-4
                                        py-2
                                        border-b
                                        rounded-2xl
                                        border-gray-300
                                        focus:outline-none focus:border-indigo-500
                                    " type="password" placeholder="请输入密码">
            </div>
            <div class="flex items-center justify-between">
              <div class="flex items-center">
                <input id="remember_me" name="remember_me" type="checkbox" class="
                                            h-4
                                            w-4
                                            bg-blue-500
                                            focus:ring-blue-400
                                            border-gray-300
                                            rounded
                                        ">
                <label for="remember_me" class="ml-2 block text-sm text-gray-900">记住我</label>
              </div>



              <!--                                <div class="text-sm">-->
              <!--                                    <a href="https://v.bootstrapmb.com/2021/8/admh611027/#" class="text-indigo-400 hover:text-blue-500">忘记密码？</a>-->
              <!--                                </div>-->
            </div>
            <div>
              <button
                @click="handleLogin"
                type="button" class="
                                        w-full
                                        flex
                                        justify-center
                                        bg-gradient-to-r
                                        from-indigo-500
                                        to-blue-600
                                        hover:bg-gradient-to-l
                                        hover:from-blue-500
                                        hover:to-indigo-600
                                        text-gray-100
                                        p-4
                                        rounded-full
                                        tracking-wide
                                        font-semibold
                                        shadow-lg
                                        cursor-pointer
                                        transition
                                        ease-in
                                        duration-500
                                    ">登 录</button>
            </div>

            <div style="font-weight: 500;font-size: 13px;letter-spacing: 1px;">
              <span>账号：用户名:demo   密码：111111</span><br/><br/>
<!--              <span>管理端账号：用户名:admin  密码：111111</span><br/><br/>-->
<!--              <span>商业合作：qq: 7827869402   vx: MAMBA_4EVER24</span><br/><br/>-->
<!--              <span> <a target="_blank" style="text-decoration: underline;" href="http://8.146.211.120:8086/"> 完整版演示 http://8.146.211.120:8086/</a></span><br/><br/>-->
              <span> <a target="_blank" style="text-decoration: underline;" href="http://8.146.211.120:8081/"> 移动端登陆 http://8.146.211.120:8081/</a></span><br/><br/>
              <span> <a target="_blank" style="text-decoration: underline;" href="https://gitee.com/ddeatrr/springboot_vue_xhs"> gitee https://gitee.com/ddeatrr/springboot_vue_xhs</a></span>

            </div>
            <!--                            <p class="-->
            <!--                                    items-center-->
            <!--                                    justify-center-->
            <!--                                    mt-10-->
            <!--                                    text-center text-md text-gray-500-->
            <!--                                ">-->
            <!--                                <span>还没有账号？</span>-->
            <!--                                <a href="http://www.bootstrapmb.com/" target="_blank" class="-->
            <!--                                        text-indigo-400-->
            <!--                                        hover:text-blue-500-->
            <!--                                        no-underline-->
            <!--                                        hover:underline-->
            <!--                                        cursor-pointer-->
            <!--                                        transition-->
            <!--                                        ease-in-->
            <!--                                        duration-300-->
            <!--                                    ">立即注册</a>-->
            <!--                            </p>-->
          </div>
        </div>
      </div>
    </div>
  </div>
  </div>
</template>

<script>
import { validUsername } from '@/utils/validate'
import {error, isEmpty, isNotEmpty} from "@/utils/index"

let timer;
export default {
  name: 'Login',
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('The password can not be less than 6 digits'))
      } else {
        callback()
      }
    }
    return {
      loginLogo: '',
      loginForm: {
        username: 'demo',
        password: '111111'
      },
      input4:'',
      loginRules: {
        username: [{ required: true, trigger: 'blur' , message: '请输入必填项'}],
        password: [{ required: true, trigger: 'blur', validator: validatePassword, message: '请输入必填项' }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined,
      logoShow:false,
      title:''
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  mounted() {
    this.loginLogo = require('@/assets/' + process.env.VUE_APP_SYSTEM_LOGO)
    this.title = process.env.VUE_APP_SYSTEM_NAME
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      console.log('提交')
      if(isNotEmpty(this.loginForm.username)&&isNotEmpty(this.loginForm.password)){

        // this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(() => {

            // this.logoShow = true
            // timer = setTimeout(()=>{
              this.$router.push({ path: this.redirect || '/' })
              // this.loading = false
            //   clearTimeout(timer);
            //   timer = setTimeout(()=>{
            //     this.logoShow = false
            //     clearTimeout(timer);
            //   },500)
            // },3000)


          }).catch(() => {
            this.loading = false
          })
    } else {
        error('请完善登陆信息！')
        return false
      }
  }
  }
}
</script>

<style scoped src="@/styles/login/tailwind.min.css"/>
<style scoped src="@/styles/login/style.css"/>



